package com.wtwd.device.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wtwd.device.dao.AppDeviceBloodOxygenMapper;
import com.wtwd.device.model.entity.DeviceBloodOxygen;
import com.wtwd.device.service.AppDeviceBloodOxygenService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AppDeviceBloodOxygenServiceImpl extends ServiceImpl<AppDeviceBloodOxygenMapper, DeviceBloodOxygen> implements AppDeviceBloodOxygenService {

    @Resource
    private AppDeviceBloodOxygenMapper appDeviceBloodOxygenMapper;

    @Override
    public List<DeviceBloodOxygen> getBloodOxygenByTime(Long deviceId, Long id, Long startTime, Long endTime) {
        return new LambdaQueryChainWrapper<>(appDeviceBloodOxygenMapper)
                .eq(DeviceBloodOxygen::getDeviceId, deviceId)
                .between(DeviceBloodOxygen::getTime, startTime, endTime)
                .ge(id != null, DeviceBloodOxygen::getId, id)
                .list();
    }

    @Override
    public DeviceBloodOxygen getLastDeviceBloodOxygenByDeviceId(Long deviceId) {
        return appDeviceBloodOxygenMapper.getLastDeviceBloodOxygenByDeviceId(deviceId);
    }

    @Override
    public List<DeviceBloodOxygen> getBloodOxygenByTotalIdGtId(Long totalId, Long id) {
        return new LambdaQueryChainWrapper<>(appDeviceBloodOxygenMapper)
                .eq(DeviceBloodOxygen::getDeviceBloodOxygenTotalId,totalId)
                .gt(id!=null,DeviceBloodOxygen::getId,id)
                .list();
    }

    @Override
    public DeviceBloodOxygen getLastDeviceBloodOxygenByTotalId(Long totalId) {
        return appDeviceBloodOxygenMapper.getLastDeviceBloodOxygenByTotalId(totalId);
    }
}
